from typing import TYPE_CHECKING, Any, Iterable, List, Optional, Iterator, Dict
from collections import deque

from chernc.treediff.gumtree.tree.abstract_tree import AbstractTree
if TYPE_CHECKING:
    from chernc.treediff.gumtree.tree.tree import TreeLike

class Type:
    NO_TYPE = "NO_TYPE"  # Placeholder for the Type class

class FakeTree(AbstractTree):
    def __init__(self, *trees: "TreeLike") -> None:
        super().__init__()
        self.children = list(trees)

    def unsupported_operation(self) -> RuntimeError:
        raise NotImplementedError("This method should not be called on a fake tree")

    def deep_copy(self) -> "TreeLike":
        copy = FakeTree()
        for child in self.get_children():
            copy.add_child(child.deep_copy())
        return copy

    def get_label(self) -> str:
        return "NO_LABEL"  # Placeholder for the NO_LABEL constant

    def get_length(self) -> int:
        return self.get_end_pos() - self.get_pos()

    def get_pos(self) -> int:
        return min(self.children, key=lambda t: t.get_pos()).get_pos()

    def get_end_pos(self) -> int:
        return max(self.children, key=lambda t: t.get_pos()).get_end_pos()

    def get_type(self) -> str:
        return Type.NO_TYPE

    def set_label(self, label: str) -> None:
        raise self.unsupported_operation()

    def set_length(self, length: int) -> None:
        raise self.unsupported_operation()

    def set_pos(self, pos: int) -> None:
        raise self.unsupported_operation()

    def set_type(self, t: str) -> None:
        raise self.unsupported_operation()

    def __str__(self) -> str:
        return "FakeTree"

    def get_metadata(self, key: str) -> Optional[object]:
        return None  # Fake nodes have no metadata

    def set_metadata(self, key: str, value: object) -> None:
        raise self.unsupported_operation()

    def get_metadata_iterator(self) -> Iterator[Any]:
        return self.EmptyEntryIterator()
